
$(function () {
    let form = layui.form
        , laydate = layui.laydate,
        laypage = layui.laypage,
        layer = layui.layer,
        table = layui.table;
    //常规用法
    laydate.render({
        elem: '#test1'
    });
    laydate.render({
        elem: '#test2'
    });

    let i = 1, j = 1, k = 1;
    $('.add-btn').click(function () {
        i++;
        addstrs1(i);
        form.render();
    });

    $('body').on("click", ".btn-del", function () {
        var pre = $(this);
        layer.confirm('确定要删除么？', {
            btn: ['确定', '取消']
        }, function () {
            $(pre).parent().parent().remove();
            layer.closeAll('dialog');
        })

        //
    });


    function getRandomNum() {
        return parseInt(Math.random() * 50);
    }
    function addstrs1(i) {
        let iNums = getRandomNum();
        let strs1;
        strs1 = '<tr>\n' +
            '                            <td style="display: none">\n' +
            '                                <input type="text" name="number[]" value="' + i + '">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text"  name="product_name[]" class="layui-input">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="need_num[]" class="layui-input">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="quota_scale[]" class="layui-input">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="checkbox" name="need_verify[]" lay-skin="primary" value = "1" title="需要">\n' +
            '                                <input type="checkbox" name="need_verify[]" lay-skin="primary" value = "2" title="不需要">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="demand[]" class="layui-input">\n' +
            '                            </td>\n' +
            '                            <td style="text-align: center"><button type="button" class="layui-btn layui-btn-sm layui-btn-danger btn-del">删除</button></td>\n' +
            '                        </tr>';
        $('.addlists').append(strs1);
        //重新渲染
        laydate.render({
            elem: '#test1' + iNums
            , trigger: 'click' //采用click弹出
        });
        laydate.render({
            elem: '#test2' + iNums
            , trigger: 'click' //采用click弹出
        });
    }

})
